package com.pig4cloud.pig.village.message.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.village.api.entity.Message;
import com.pig4cloud.pig.village.message.service.IMessageService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author limbray.li
 * @date 2021/7/25
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/message")
@Api(value = "message", tags = "app消息管理")
public class MessageController {
	@Resource
	private IMessageService messageService;

	@GetMapping("/page")
	public R<IPage<Message>> page(Integer pageNum, Integer pageSize) {
		return R.ok(messageService.page(new Page(pageNum, pageSize)));
	}

	@PostMapping("/update")
	public R update(@RequestBody Message message) {
		return R.ok(messageService.updateById(message));
	}

	@GetMapping("/get")
	public R<Message> get(Long id) {
		return R.ok(messageService.getById(id));
	}

	@PutMapping("/deleteById")
	public R delete(Long id) {
		return R.ok(messageService.removeById(id));
	}

	@PostMapping("/add")
	public R add(@RequestBody Message message) {
		return R.ok(messageService.save(message));
	}
}
